From e0cdd3769dc313337744f022c010f48a4326af5b Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Thu, 18 Sep 2014 10:49:43 -0700 Subject: [PATCH] add codegen-units option to profile section --- src/cargo/core/manifest.rs | 14 +++++++++++++- src/cargo/ops/cargo_rustc/mod.rs | 5 +++++ src/cargo/util/toml.rs | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index dc6d27f63..1b714c5a5 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -107,6 +107,7 @@ pub enum TargetKind { pub struct Profile { env: String, // compile, test, dev, bench, etc. opt_level: uint, + codegen_units: Option, // None = use rustc default debug: bool, test: bool, doctest: bool, @@ -121,6 +122,7 @@ impl Profile { Profile { env: String::new(), opt_level: 0, + codegen_units: None, debug: false, test: false, doc: false, @@ -206,6 +208,10 @@ impl Profile { self.opt_level } + pub fn get_codegen_units(&self) -> Option { + self.codegen_units + } + pub fn get_debug(&self) -> bool { self.debug } @@ -223,6 +229,11 @@ impl Profile { self } + pub fn codegen_units(mut self, units: Option) -> Profile { + self.codegen_units = units; + self + } + pub fn debug(mut self, debug: bool) -> Profile { self.debug = debug; self @@ -260,6 +271,7 @@ impl hash::Hash for Profile { // to the actual hash of a profile. let Profile { opt_level, + codegen_units, debug, plugin, dest: ref dest, @@ -273,7 +285,7 @@ impl hash::Hash for Profile { test: _, doctest: _, } = *self; - (opt_level, debug, plugin, dest, harness).hash(into) + (opt_level, codegen_units, debug, plugin, dest, harness).hash(into) } } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index a94d93ae1..40e58cdac 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -352,6 +352,11 @@ fn build_base_args(cx: &Context, mut cmd: ProcessBuilder, cmd = cmd.arg("--opt-level").arg(profile.get_opt_level().to_string()); } + match profile.get_codegen_units() { + Some(n) => cmd = cmd.arg("-C").arg(format!("codegen-units={}", n)), + None => {}, + } + if profile.get_debug() { cmd = cmd.arg("-g"); } else { diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index ec2e675ff..fe5c6c04f 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -221,6 +221,7 @@ pub struct TomlProfiles { #[deriving(Decodable, Clone, Default)] pub struct TomlProfile { opt_level: Option, + codegen_units: Option, debug: Option, } @@ -604,8 +605,9 @@ fn normalize(libs: &[TomlLibTarget], None => return profile, }; let opt_level = toml.opt_level.unwrap_or(profile.get_opt_level()); + let codegen_units = toml.codegen_units; let debug = toml.debug.unwrap_or(profile.get_debug()); - profile.opt_level(opt_level).debug(debug) + profile.opt_level(opt_level).codegen_units(codegen_units).debug(debug) } fn target_profiles(target: &TomlTarget, profiles: &TomlProfiles, -- 2.30.2